
clear all
set more off
capture log close
est clear

global tableA1A2 		0 // 1: run, 0: not  (TO CHECK)

global tableB1 			0 // 1: run, 0: not 
global tableB2 			0 // 1: run, 0: not 
global tableB3 			0 // 1: run, 0: not 
global tableB4 			0 // 1: run, 0: not 
global tableB5 			0 // 1: run, 0: not 

global tableC1 			0 // 1: run, 0: not 
global tableC2 			0 // 1: run, 0: not 



*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* beliefs decomposition *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableA1A2 == 1 {
	
use "data/working/data_platform.dta", clear

*------------------------------------------------------------------------------*
* Variables *
*------------------------------------------------------------------------------*

sort currency_id
encode currency_id, gen(currency_id_num)

merge m:1 date using "data/working/googlesearchbydates.dta"	
keep if _merge ==3

*------------------------------------------------------------------------------*
* Estimation *
*------------------------------------------------------------------------------*

local google 	dgoogle_value_bitcoin google_hack_bitcoin 
local googlel7 	l7_dgoogle_value_bitcoin l7_google_hack_bitcoin // 
local control 	incomenewdummy agenewdummy countrynewdummy type_objective // 
rename first_time first_time_late
gen first_time_early = (first_purcha!="" & first_time_late==0)

gen long_increase = -long_decrease + 1

foreach var in short_increase long_increase {
	* google
	reg `var' `google', robust
					estadd local fe_time 		"No"
					estadd local demo 			"No"
					estadd ysumm
	est sto `var'_1

	* google
	reg `var' `googlel7', robust
					estadd local fe_time 		"No"
					estadd local demo 			"No"
					estadd ysumm
	est sto `var'_2

	* time fixed effects
	reg `var' i.date, robust
					estadd local fe_time 		"Yes"
					estadd local demo 			"No"
					estadd ysumm
	est sto `var'_3

	* time fixed effects + characteristics
	reg `var' i.date `control' , robust
					estadd local fe_time 		"Yes"
					estadd local demo 			"Yes"
					estadd ysumm
	est sto `var'_4

	* time fixed effects + characteristics + early/late buyer	
	reg `var' i.date `control'  1.first_time_early 1.first_time_late , robust
					estadd local fe_time 		"Yes"
					estadd local demo 			"Yes"
					estadd ysumm
	est sto `var'_5
	
}

*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*
	
esttab 	short_increase* long_increase* ///
		using "output/tables/tableA1.tex", replace booktabs b(3) se(3) ///
			keep(dgoogle_value_bitcoin google_hack_bitcoin l7_dgoogle_value_bitcoin l7_google_hack_bitcoin 1.first_time_early 1.first_time_late ) ///
			order(dgoogle_value_bitcoin google_hack_bitcoin l7_dgoogle_value_bitcoin l7_google_hack_bitcoin 1.first_time_early 1.first_time_late ) ///
			coeflabel(dgoogle_value_bitcoin "\quad Bitcoin (same day)" ///
						google_hack_bitcoin "\quad Bitcoin hack (same day)" ///
						l7_dgoogle_value_bitcoin "\quad Bitcoin (previous week)" ///
						l7_google_hack_bitcoin "\quad Bitcoin hack (previous week)" ///
						1.first_time_early "Early Buyer" ///
						1.first_time_late "Late Buyer") ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(fe_time demo ymean ysd r2 N, fmt(0 0 2 2 2 %9.0fc) ///
							labels( "Time f.e." "Demographics"  "Mean Y" "SD Y" "R2" "Observations" ) )  ///
			refcat(dgoogle_value_bitcoin "\emph{Google search:}" , nolabel) ///				
			mgroups("\textsc{Short-term Optimism}" "\textsc{Long-term Optimism}", pattern(1 0 0 0 0 1 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitle eqlabel(none)  //				

est clear


*------------------------------------------------------------------------------*
* Estimation *
*------------------------------------------------------------------------------*

* currency fixed effects
reg currencies_potential i.currency_id_num
				estadd local fe_currency 		"Yes"
				estadd local fe_time 			"No"
				estadd local fe_currencytime  	"No"
				estadd local fe_individual  	"No"
				estadd ysumm
est sto tmp1

* time fixed effects
reg currencies_potential i.date
				estadd local fe_currency 		"No"
				estadd local fe_time 			"Yes"
				estadd local fe_currencytime  	"No"
				estadd local fe_individual  	"No"
				estadd ysumm
est sto tmp2

* currency and time fixed effects
reg currencies_potential i.date i.currency_id_num
				estadd local fe_currency 		"Yes"
				estadd local fe_time 			"Yes"
				estadd local fe_currencytime  	"No"
				estadd local fe_individual  	"No"
				estadd ysumm
est sto tmp3

* currency - time fixed effects
reg currencies_potential i.currency_id_num##i.date
				estadd local fe_currency 		"No"
				estadd local fe_time 			"No"
				estadd local fe_currencytime  	"Yes"
				estadd local fe_individual  	"No"
				estadd ysumm
est sto tmp4

* individual fixed effects
areg currencies_potential, abs(household_id)
				estadd local fe_currency 		"No"
				estadd local fe_time 			"No"
				estadd local fe_currencytime  	"No"
				estadd local fe_individual  	"Yes"
				estadd ysumm
est sto tmp5

* individual and currency fixed effects
areg currencies_potential i.currency_id_num, abs(household_id)
				estadd local fe_currency 		"Yes"
				estadd local fe_time 			"No"
				estadd local fe_currencytime  	"No"
				estadd local fe_individual  	"Yes"
				estadd ysumm
est sto tmp6


*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*
	
esttab 	tmp* ///
		using "output/tables/tableA2.tex", replace booktabs b(3) se(3) ///
			drop(*currency_id_num* *date* _cons) ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(fe_currency fe_time fe_currencytime fe_individual ymean ysd r2 N, fmt(0 0 0 0 2 2 2 %9.0fc) ///
							labels( "Cryptocurrency f.e."  "Time f.e." "Currency $\times$ time f.e." "Individual f.e." "Mean Y" "SD Y" "R2" "Observations" ) )  ///
			mgroups("\textsc{Decomposition of high potential}", pattern(1 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) nomtitle eqlabel(none)  //				

est clear

}


*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* firststage *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableB1 == 1 {
	

*------------------------------------------------------------------------------*
* Market cap *
*------------------------------------------------------------------------------*

	* column 1: baseline
	est use "output/estimates/tableB1a_col1_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)		
	est use "output/estimates/tableB1a_col1.ster"
		ereturn disp 
		estadd local controls_macro "Yes"
		estadd local controls_demo	"Yes"
		estadd local wave_fe		"No"
		estadd local time_fe		"No"
		estadd scalar Fexcluded = iv[4,1]		
	est sto fs_1	

	* column 2: wave fe
	est use "output/estimates/tableB1a_col2_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)
	est use "output/estimates/tableB1a_col2.ster"
		ereturn disp
		estadd local controls_macro "Yes"
		estadd local controls_demo	"Yes"
		estadd local wave_fe		"Yes"
		estadd local time_fe		"No"	
		estadd scalar Fexcluded = iv[4,1] 	
	est sto fs_2	

	* column 3: time fe
	est use "output/estimates/tableB1a_col3_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)	
	est use "output/estimates/tableB1a_col3.ster"
		ereturn disp
		estadd local controls_macro "Yes"
		estadd local controls_demo	"Yes"
		estadd local wave_fe		"No"
		estadd local time_fe		"Yes"
		estadd scalar Fexcluded = iv[4,1] 	
	est sto fs_3	


*------------------------------------------------------------------------------*
* Price *
*------------------------------------------------------------------------------*

	* column 4: baseline
	est use "output/estimates/tableB1a_col4_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)		
	est use "output/estimates/tableB1a_col4.ster"
		ereturn disp
		estadd local controls_macro "Yes"
		estadd local controls_demo	"Yes"
		estadd local wave_fe		"No"
		estadd local time_fe		"No"
		estadd scalar Fexcluded = iv[4,1] 	
	est sto fs_4	

	* column 5: wave fe
	est use "output/estimates/tableB1a_col5_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)		
	est use "output/estimates/tableB1a_col5.ster"
		ereturn disp
		estadd local controls_macro "Yes"
		estadd local controls_demo	"Yes"
		estadd local wave_fe		"Yes"
		estadd local time_fe		"No"
		estadd scalar Fexcluded = iv[4,1] 	
	est sto fs_5	


	* column 6: time fe
	est use "output/estimates/tableB1a_col6_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)	
	est use "output/estimates/tableB1a_col6.ster"
		ereturn disp
		estadd local controls_macro "Yes"
		estadd local controls_demo	"Yes"
		estadd local wave_fe		"No"
		estadd local time_fe		"Yes"
		estadd scalar Fexcluded = iv[4,1] 	
	est sto fs_6	


*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*

	esttab 	fs_* ///
			using "output/tables/tableB1a.tex", replace booktabs b(3) se(3) ///
				keep(logsupply ) ///
				order(logsupply ) ///
				coeflabel(logsupply "Log supply") ///
				star(* 0.10 ** 0.05 *** 0.01) nonotes stats(controls_macro controls_demo wave_fe time_fe Fexcluded r2 N, fmt(0 0 0 0 0 2 %9.0fc) ///
								labels( "Macro controls" "Demographics controls" "Wave f.e." "Time f.e." "First-Stage F" "R$^2$" "Observations" ) )  ///
				mgroups("\textsc{\shortstack{Dependent variable:\\Market capitalization (log)}}" "\textsc{\shortstack{Dependent variable:\\Price (log)}}", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
				nomtitle eqlabel(none) ///

	est clear



*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* Full sample *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*



*------------------------------------------------------------------------------*
* Market cap *
*------------------------------------------------------------------------------*

	* column 1: baseline
	est use "output/estimates/tableB1b_col1_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)			
	est use "output/estimates/tableB1b_col1.ster"
		ereturn disp
		estadd local time_fe		"No"
		estadd local crypto_fe		"No"
		estadd scalar Fexcluded = iv[4,1] 			
	est sto fs_1	

	* column 2: wave fe
	est use "output/estimates/tableB1b_col2_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)			
	est use "output/estimates/tableB1b_col2.ster"
		ereturn disp
		estadd local time_fe		"Yes"
		estadd local crypto_fe		"No"
		estadd scalar Fexcluded = iv[4,1] 			
	est sto fs_2	


	* column 3: time fe
	est use "output/estimates/tableB1b_col3_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)		
	est use "output/estimates/tableB1b_col3.ster"
		ereturn disp
		estadd local time_fe		"Yes"
		estadd local crypto_fe		"Yes"
		estadd scalar Fexcluded = iv[4,1] 			
	est sto fs_3	


*------------------------------------------------------------------------------*
* Price *
*------------------------------------------------------------------------------*

	* column 4: baseline
	est use "output/estimates/tableB1b_col4_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)			
	est use "output/estimates/tableB1b_col4.ster"
		ereturn disp
		estadd local time_fe		"No"
		estadd local crypto_fe		"No"
		estadd scalar Fexcluded = iv[4,1] 			
	est sto fs_4	

	* column 5: wave fe
	est use "output/estimates/tableB1b_col5_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)		
	est use "output/estimates/tableB1b_col5.ster"
		ereturn disp
		estadd local time_fe		"Yes"
		estadd local crypto_fe		"No"
		estadd scalar Fexcluded = iv[4,1] 			
	est sto fs_5	


	* column 6: time fe
	est use "output/estimates/tableB1b_col6_Fstat.ster"
		ereturn disp
		matrix list e(first)
		matrix iv=e(first)		
	est use "output/estimates/tableB1b_col6.ster"
		ereturn disp
		estadd local time_fe		"Yes"
		estadd local crypto_fe		"Yes"
		estadd scalar Fexcluded = iv[4,1] 			
	est sto fs_6	


*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*

esttab 	fs_* ///
		using "output/tables/tableB1b.tex", replace booktabs b(3) se(3) ///
			keep(logsupply ) ///
			order(logsupply ) ///
			coeflabel(logsupply "Log supply") ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(time_fe crypto_fe Fexcluded r2 N, fmt(0 0 0 2 %9.0fc) ///
							labels( "Time f.e." "Cryptocurrency f.e." "First-Stage F" "R$^2$" "Observations" ) )  ///
			mgroups("\textsc{\shortstack{Dependent variable:\\Market capitalization (log)}}" "\textsc{\shortstack{Dependent variable:\\Price (log)}}", pattern(1 0 0 1 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
			nomtitle eqlabel(none) ///

est clear

	
}
	

*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* demand_robustness *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableB2 == 1 {
	

* column 1: dep weighted
est use "output/estimates/tableB2_col1"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_1	

* column 2: equally weighted
est use "output/estimates/tableB2_col2"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_2	


* column 3: wealth level factor 3
est use "output/estimates/tableB2_col3"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_3	


* column 4: wealth level factor 4
est use "output/estimates/tableB2_col4"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_4	


* column 5: wealth level factor 5
est use "output/estimates/tableB2_col5"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_5	


* column 6: wealth level factor 7
est use "output/estimates/tableB2_col6"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_6


*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*

esttab 	robust_* ///
		using "output/tables/tableB2.tex", replace booktabs b(3) se(3) ///
			keep(logME pow beta momentum4 short_increase long_decrease currencies_potential) ///
			order(logME pow beta momentum4 short_increase long_decrease currencies_potential) ///
			coeflabel(	logME "\quad Market capitalization" pow "\quad Proof-of-Work" ///
						beta "\quad Beta" momentum4 "\quad Four-week momentum" ///
						short_increase "\quad Price Increase"  ///
						long_decrease 	"\quad Never Mainstream"  currencies_potential "\quad High Potential"  ///
						) ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(controls_macro controls_demo N, fmt(0 0 %9.0fc) ///
							labels( "Macro controls" "Demographics controls" "Observations" ) )  ///
			refcat(logME "\emph{Characteristics:}" short_increase "\emph{Beliefs:}", nolabel) ///
			mgroups("\textsc{Portfolio share}" "\textsc{Wealth-Income ratio}", pattern(1 0 1 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
			mtitle("\textsc{\shortstack{Weighted\\by group}}" "\textsc{\shortstack{Equally\\weighted}}" "\textsc{3x}" "\textsc{4x}" "\textsc{5x}" "\textsc{7x}") eqlabel(none) ///

est clear
	
	
}	


*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* demand_additionalcontrol *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableB3 == 1 {
	

* column 1: also short decrease
est use "output/estimates/tableB3_col1"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"No"
est sto robust_1	

* column 2: wave fixed effects
est use "output/estimates/tableB3_col2"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"Yes"	
est sto robust_2	


* column 3: consider
est use "output/estimates/tableB3_col3"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"No"	
est sto robust_3	


* column 4: remove Ripple (only PoW crypto)
est use "output/estimates/tableB3_col4"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"No"	
est sto robust_4	


* column 5: add age of the crypto
est use "output/estimates/tableB3_col5"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"No"	
est sto robust_5	


* column 6: add age of the crypto with white paper
est use "output/estimates/tableB3_col6"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"No"	
est sto robust_6

* column 7: add beliefs interactions
est use "output/estimates/tableB3_col7"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"No"	
est sto robust_7


* column 8: add average beliefs
est use "output/estimates/tableB3_col8"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
	estadd local wave_fe		"No"	
est sto robust_8


*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*

esttab 	robust_* ///
		using "output/tables/tableB3.tex", replace booktabs b(3) se(3) ///
			keep(logME pow beta momentum4 short_increase long_decrease currencies_potential short_decrease company_consider cage cage_whitepaper 1.short_increase#1.long_decrease 1.short_increase#1.currencies_potential 1.long_decrease#1.currencies_potential 1.short_increase#1.long_decrease#1.currencies_potential /// 
					ot_currencies_potential) ///
			order(logME pow beta momentum4 short_increase long_decrease currencies_potential short_decrease company_consider cage cage_whitepaper 1.short_increase#1.long_decrease 1.short_increase#1.currencies_potential 1.long_decrease#1.currencies_potential 1.short_increase#1.long_decrease#1.currencies_potential /// 
					ot_currencies_potential) ///
			coeflabel(	logME "\quad Market capitalization" pow "\quad Proof-of-Work" ///
						beta "\quad Beta" momentum4 "\quad Four-week momentum" ///
						short_increase "\quad Price Increase"  short_decrease "\quad Price Decrease" ///
						long_decrease 	"\quad Never Mainstream"  currencies_potential "\quad High Potential"  ///
						company_consider "\quad Company consider" ///
						cage "\quad Cryptocurrency age (launch)" cage_whitepaper "\quad Cryptocurrency age (white paper)" ///
						1.short_increase#1.long_decrease 						"\quad Price Increase $\times$ Never Mainstream" ///
						1.short_increase#1.currencies_potential 				"\quad Price Increase $\times$ High Potential" ///
						1.long_decrease#1.currencies_potential 					"\quad Never Mainstream $\times$ High Potential" ///
						1.short_increase#1.long_decrease#1.currencies_potential "\quad Price Increase $\times$ Never Mainstream $\times$ High Potential" ///
						ot_currencies_potential 								"\quad High Potential (Other Cryptocurrencies)") ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(controls_macro controls_demo wave_fe N, fmt(0 0 0 %9.0fc) ///
							labels( "Macro controls" "Demographics controls" "Wave f.e." "Observations" ) )  ///
			refcat(logME "\emph{Characteristics:}" short_increase "\emph{Beliefs:}" short_decrease "\emph{Additional controls:}", nolabel) ///
			mgroups("\textsc{Additional controls}", pattern(1 0 0 0 0 0 0 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
			nomtitle eqlabel(none) ///

est clear
		
	
}

	
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* demand_googlenetwork *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableB4 == 1 {
	

* column 1: add Google search deviation for Bitcoin 
est use "output/estimates/tableB4_col1.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_1	

* column 2: add Google search hack ratio for Bitcoin 
est use "output/estimates/tableB4_col2.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_2	

* column 3: add Google search deviation by Bitcoin (lag 7 days)
est use "output/estimates/tableB4_col3.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_3	

* column 4: add Google search hack ratio for Bitcoin (lag 7 days)
est use "output/estimates/tableB4_col4.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_4	

* column 5: add network Bitcoin
est use "output/estimates/tableB4_col5.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_5	

* column 6: add network Bitcoin
est use "output/estimates/tableB4_col6.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto robust_6

*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*

esttab 	robust_* ///
		using "output/tables/tableB4.tex", replace booktabs b(3) se(3) ///
			keep(logME pow beta momentum4 short_increase long_decrease currencies_potential dgoogle_value_Bitcoin google_hack_Bitcoin l7_dgoogle_value_Bitcoin l7_google_hack_Bitcoin d_log_num_activeaddress_Bitcoin d_log_num_newaddress_Bitcoin) ///
			order(logME pow beta momentum4 short_increase long_decrease currencies_potential dgoogle_value_Bitcoin google_hack_Bitcoin l7_dgoogle_value_Bitcoin l7_google_hack_Bitcoin d_log_num_activeaddress_Bitcoin d_log_num_newaddress_Bitcoin) ///
			coeflabel(	logME "\quad Market capitalization" pow "\quad Proof-of-Work" ///
						beta "\quad Beta" momentum4 "\quad Four-week momentum" ///
						short_increase "\quad Price Increase"  ///
						long_decrease 	"\quad Never Mainstream"  currencies_potential "\quad High Potential"  ///
						dgoogle_value_Bitcoin "\quad Google search: Bitcoin (same day)" google_hack_Bitcoin "\quad Google search: Bitcoin hack (same day)" ///
						l7_dgoogle_value_Bitcoin "\quad Google search: Bitcoin (previous week)" l7_google_hack_Bitcoin "\quad Google search: Bitcoin hack (previous week)" ///
						d_log_num_activeaddress_Bitcoin "\quad Active addresses: Bitcoin (Change)" d_log_num_newaddress_Bitcoin "\quad New addresses: Bitcoin (Change)" ) ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(controls_macro controls_demo N, fmt(0 0 %9.0fc) ///
							labels( "Macro controls" "Demographics controls" "Observations" ) )  ///
			refcat(logME "\emph{Characteristics:}" short_increase "\emph{Beliefs:}" ///
			dgoogle_value_Bitcoin "\emph{Proxies for attention:}" d_log_num_activeaddress_Bitcoin "\emph{Proxies for network:}", nolabel) ///
			mgroups("\textsc{Proxies for Attention}" "\textsc{Proxies for Network}", pattern(1 0 0 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) ///
			nomtitle  eqlabel(none) ///

est clear
		
		
}


*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* demand_fit *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableB5 == 1 {


* column 1: only characteristics
est use "output/estimates/tableB5_col1.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto main_1	

* column 2: + short-term beliefs
est use "output/estimates/tableB5_col2.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto main_2	

* column 3: + never mainstream
est use "output/estimates/tableB5_col3.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto main_3	

* column 4: + high potential 
est use "output/estimates/tableB5_col4.ster"
	ereturn disp
	estadd local controls_macro "Yes"
	estadd local controls_demo	"Yes"
est sto main_4	


*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*

esttab 	main_* ///
		using "output/tables/tableB5.tex", replace booktabs b(3) se(3) ///
			keep(logME pow beta momentum4 short_increase long_decrease currencies_potential) ///
			order(logME pow beta momentum4 short_increase long_decrease currencies_potential) ///
			coeflabel(	logME "\quad Market capitalization" pow "\quad Proof-of-Work" ///
						beta "\quad Beta" momentum4 "\quad Four-week momentum" ///
						short_increase "\quad Price Increase"  /// 1.short_increase#1.not_casual "\quad Price Increase $\times$ Accredited Investor" ///
						long_decrease 	"\quad Never Mainstream"  currencies_potential "\quad High Potential"  ) ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(controls_macro controls_demo N, fmt(0 0 %9.0fc) ///
							labels( "Macro controls"  "Demographics controls" "Observations" ) )  ///
			refcat(logME "\emph{Characteristics:}" short_increase "\emph{Beliefs:}", nolabel) eqlabel(none) //		

est clear

}



*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* sumstat others *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableC1 == 1 {

*------------------------------------------------------------------------------*
* Table C1a *
*------------------------------------------------------------------------------*


use "data/working/working_scpc.dta", clear

eststo scpc: estpost sum age income_new male loweducation assetdummy  ///
				bitcoin_heardof bitcoin_own bitcoin_familiar bitcoin_transaction ///
				exp_inc_year exp_dec_year, detail

esttab using "output/tables/tableC1a.tex", ///
							cells("count(fmt(%12.0fc)) mean(fmt(%12.2fc)) sd(fmt(%12.2fc)) min(fmt(%12.2fc)) p50(fmt(%12.2fc)) max(fmt(%12.2fc))") ///
							refcat(age "\emph{Demographics:}" bitcoin_heardof "\emph{Cryptocurrency questions (general):}" ///
										exp_inc_year "\emph{Cryptocurrency questions (beliefs):}", nolabel) ///
							coeflabel(age "\quad Age" income_new "\quad Income (dollars)" male "\quad Male" ///
								loweducation "\quad Education (Below Bachelor)" assetdummy  "\quad Asset $\leq$20K" ///
								bitcoin_heardof "\quad Awareness" bitcoin_own "\quad Holding" ///
								bitcoin_familiar "\quad Familiarity" bitcoin_transaction "\quad Usage for transaction" ///
								exp_inc_year "\quad Increase" exp_dec_year "\quad Decrease") ///
							collabels("Observations" "Mean" "Std. Dev." "Minimum" "Median" "Maximum") ///
							noobs label nomtitle eqlabels(none) replace
est clear


*------------------------------------------------------------------------------*
* Table C1b *
*------------------------------------------------------------------------------*


use "data/working/working_ING.dta", clear

eststo ing: estpost sum age income male edu nonstandardemploy  ///
				heard own expect_own ///
				exp_inc exp_dec, detail

esttab using "output/tables/tableC1b.tex", ///
							cells("count(fmt(%12.0fc)) mean(fmt(%12.2fc)) sd(fmt(%12.2fc)) min(fmt(%12.2fc)) p50(fmt(%12.2fc)) max(fmt(%12.2fc))") ///
							refcat(age "\emph{Demographics:}" heard "\emph{Cryptocurrency questions (general):}" ///
										exp_inc "\emph{Cryptocurrency questions (beliefs):}", nolabel) ///
							coeflabel(age "\quad Age" income "\quad Income (euros)" male "\quad Male" ///
								edu "\quad Education (Below Bachelor)" nonstandardemploy  "\quad Non-standard employment" ///
								heard "\quad Awareness" own "\quad Holding" expect_own "\quad Holding (expected)" ///
								exp_inc "\quad Increase" exp_dec "\quad Decrease") ///
							collabels("Observations" "Mean" "Std. Dev." "Minimum" "Median" "Maximum") ///
							noobs label nomtitle eqlabels(none) replace
est clear

}


*------------------------------------------------------------------------------**------------------------------------------------------------------------------*
* reduced-form others *
*------------------------------------------------------------------------------**------------------------------------------------------------------------------*

if $tableC2 == 1 {
	
*------------------------------------------------------------------------------*
* SCPC *
*------------------------------------------------------------------------------*

use "data/working/working_scpc.dta", clear

gen bitcoin_expectation_nextyear_3 		= .
replace bitcoin_expectation_nextyear_3 	= -1 	if bitcoin_expectation_nextyear == 1 | bitcoin_expectation_nextyear == 2
replace bitcoin_expectation_nextyear_3 	= 0 	if bitcoin_expectation_nextyear == 3
replace bitcoin_expectation_nextyear_3 	= 1 	if bitcoin_expectation_nextyear == 4 | bitcoin_expectation_nextyear == 5

gen high_familiar = bitcoin_familiar>3

gen year=year(date) 

local control incomenewdummy  agenewdummy 1.male 1.loweducation assetdummy i.year

ologit bitcoin_expectation_nextyear_3 `control', r
				estadd local fe_year 		"Yes"
				estadd local fe_country		"No"
				estadd ysumm
est store belief_scpc

ologit bitcoin_expectation_nextyear_3 `control', or

reg bitcoin_own exp_inc_year exp_dec_year `control'
				estadd local fe_year 		"Yes"
				estadd local fe_country		"No"
				estadd ysumm
est store demand_scpc

reg bitcoin_own exp_inc_year exp_dec_year 1.high_familiar 1.exp_inc_year#1.high_familiar 1.exp_dec_year#1.high_familiar `control'
				estadd local fe_year 		"Yes"
				estadd local fe_country		"No"
				estadd ysumm
est store demand_scpc2
	
*------------------------------------------------------------------------------*
* ING *
*------------------------------------------------------------------------------*
	

use "data/working/working_ING.dta", clear

gen crypto_dummy = crypto_own == "Yes"

gen exp_3 		= .
replace exp_3 	= -1 	if exp == 0 | exp == 1
replace exp_3 	= 0 	if exp == 2
replace exp_3 	= 1 	if exp == 3 | exp == 4


* to have the same name as in scpc 
rename exp_inc exp_inc_year
rename exp_dec exp_dec_year
rename edu loweducation

*local control incomenewdummy  agenewdummy i.male i.loweducation assetdummy log_sp500 log_libor i.year
local control  incomenewdummy agenewdummy 1.male 1.loweducation nonstandardemploy i.Country_id

ologit exp_3 `control', r
				estadd local fe_year 		"No"
				estadd local fe_country		"Yes"
				estadd ysumm
est store belief_ing

ologit exp_3 `control', or

reg crypto_dummy exp_inc_year exp_dec_year `control'
				estadd local fe_year 		"No"
				estadd local fe_country		"Yes"
				estadd ysumm
est store demand_ing
	
	
*------------------------------------------------------------------------------*
* Table *
*------------------------------------------------------------------------------*
	
esttab 	belief_scpc	demand_scpc demand_scpc2 ///
		belief_ing	demand_ing ///
		using "output/tables/tableC2.tex", replace booktabs b(3) se(3) ///
			keep(exp_inc_year exp_dec_year 1.exp_inc_year#1.high_familiar 1.exp_dec_year#1.high_familiar ///
					incomenewdummy agenewdummy 1.male 1.loweducation assetdummy nonstandardemploy ) ///  1.high_familiar 
			order(exp_inc_year exp_dec_year 1.exp_inc_year#1.high_familiar 1.exp_dec_year#1.high_familiar ///
					incomenewdummy agenewdummy 1.male 1.loweducation assetdummy nonstandardemploy ) ///   1.high_familiar 
			coeflabel(exp_inc_year "\quad Increase" exp_dec_year "\quad Decrease" ///
						incomenewdummy "\quad Low income" agenewdummy "\quad Age $\leq$ 45"  ///
						1.male "\quad Male" 1.loweducation "\quad Education (Below bachelor)" ///
						assetdummy "\quad Asset $\leq$ 20K" nonstandardemploy "\quad Non-standard employment"  ///
						1.exp_inc_year#1.high_familiar "\quad Increase $\times$ High familiarity" ///
						1.exp_dec_year#1.high_familiar "\quad Decrease $\times$ High familiarity" ) /// 1.high_familiar "\quad High familiarity" ///
			star(* 0.10 ** 0.05 *** 0.01) nonotes stats(fe_year fe_country ymean ysd r2_p r2_a N, fmt(0 0 2 2 2 2 %9.0fc) /// 
							labels( "Year f.e." "Country f.e." "Mean Y" "SD Y" "Pseudo R2" "Adjusted R2" "Observations" ) )  ///
			mgroups("\textsc{SCPC}" "\textsc{ING}", pattern(1 0 0 1 0) prefix(\multicolumn{@span}{c}{) suffix(}) span erepeat(\cmidrule(lr){@span})) /// 
			mtitle("Beliefs" "Demand" "Demand" "Beliefs" "Demand")  /// nonumber
			refcat(exp_inc_year "\emph{Beliefs:}" incomenewdummy "\emph{Demographics:}", nolabel) //

est clear
							

							
}	
